package com.yueka.mapper;

import com.yueka.pojo.system_user.LoginInfo;
import com.yueka.pojo.system_user.SystemUser;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Value;

import java.util.List;

@Mapper
public interface SystemUserMapper {
    @Select("select s.id as id, username, system_user_name, avatar, permissions, email, phone from system_user s left join role r on s.role_id = r.id where username = #{username} and password = #{password}")
    LoginInfo getSystemUserByUsernameAndPassword(SystemUser systemUser);

    @Insert("insert into system_user (username, password, system_user_name, create_time, update_time) VALUES (#{username}, #{password}, #{systemUserName}, #{createTime}, #{updateTime})")
    Integer register(SystemUser systemUser);

    List<SystemUser> getList(String keyword, String status);

    @Update("update system_user set system_user_name = #{systemUserName}, email = #{email}, phone = #{phone}, avatar = #{avatar}, status = #{status}, role_id = #{roleId}, update_time = #{updateTime} where id = #{id}")
    Integer update(SystemUser systemUser);

    @Insert("insert into system_user (username, system_user_name, email, phone, avatar, status, role_id, create_time, update_time) VALUES (#{username}, #{systemUserName}, #{email}, #{phone}, #{avatar}, #{status}, #{roleId}, #{createTime}, #{updateTime})")
    Integer insert(SystemUser systemUser);

    Integer delete(Integer[] ids);

    @Select("select id, username, password, system_user_name, email, phone, avatar, status, role_id, create_time, update_time from system_user where id = #{id} and password = #{oldPassword}")
    SystemUser verificationPassword(Integer id, String oldPassword);

    @Insert("update system_user set password = #{newPassword} where id = #{id}")
    void updatePassword(Integer id, String newPassword);

    @Update("update system_user set system_user_name = #{systemUserName}, email = #{email}, phone = #{phone}, avatar = #{avatar}, update_time = #{updateTime} where id = #{id}")
    void updatePersonal(SystemUser systemUser);

    @Update("update system_user set password = #{defaultPassword} where id = #{id}")
    void resetPassword(Integer id, String defaultPassword);
}
